home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1997 August / Walnut Creek CDROM.7z / VOL_400 / 460_01 / YACL0160.ZIP / uidemo / combobox / appwin.cxx next >
Encoding:
C/C++ Source or Header  |  1996-10-11  |  2.4 KB  |  91 lines

  1.  
  2. #include "appwin.h"
  3. #include "ui/stddlg.h"
  4. #include "ui/applic.h"
  5.  
  6.  
  7.  
  8. enum {
  9.     ID_BUTTON0 = 10,
  10.     ID_BUTTON1,
  11.     ID_LABEL0,
  12.     ID_LABEL1,
  13.     ID_BOX0,
  14.     ID_BOX1
  15. };
  16.  
  17.  
  18.  
  19. static void AddModelStrings (UI_ComboBox* box)
  20. {
  21.     UI_StringSequence& model = (UI_StringSequence&) box->Model();
  22.     model.Add ("Word for Windows");
  23.     model.Add ("WordPerfect");
  24.     model.Add ("Freelance");
  25.     model.Add ("PowerPoint");
  26.     model.Add ("CorelDraw!");
  27.     model.Add ("PC Anywhere");
  28.     model.Add ("Carbon Copy");
  29.     model.Add ("Paradox");
  30.     model.Add ("Eudora");
  31.     model.Add ("Pegasus Mail");
  32. }
  33.  
  34.  
  35. AppWindow::AppWindow()
  36. : UI_Dialog (NULL, NULL, UI_Rectangle (40, 40, 510, 200))
  37. {
  38.     _btn0  = new UI_PushButton (this, UI_Rectangle (240, 150, 130, 30),
  39.                                 ID_BUTTON0);
  40. //     _btn1  = new UI_PushButton (this, UI_Rectangle (245, 150, 130, 30),
  41. //                                 ID_BUTTON1);
  42.     _lbl0  = new UI_Label    (this, UI_Rectangle (15, 50, 235, 20),
  43.                               ID_LABEL0);
  44.     _lbl1  = new UI_Label    (this, UI_Rectangle (260, 50, 235, 20),
  45.                               ID_LABEL1);
  46.     _box0  = new UI_ComboBox (this, UI_Rectangle (15, 90, 235, 40), ID_BOX0,
  47.                               100, FALSE);
  48.     _box1  = new UI_ComboBox (this, UI_Rectangle (260, 90, 235, 40), ID_BOX1,
  49.                               100, TRUE);
  50.  
  51.     AddModelStrings (_box0);
  52.     AddModelStrings (_box1);
  53.     _btn0->Title() = "Select next";
  54. //    _btn1->Title() = "Select next";
  55.     _title = "YACL ComboBox Demo";
  56.     _box0->Selection () = 3; // Select PowerPoint
  57. }
  58.  
  59. bool AppWindow::HandleChildEvent (const UI_Event& e)
  60. {
  61.     if (e.Type() != Event_Select)
  62.         return FALSE;
  63.     switch (e.Origin()->ViewID()) {
  64.     case ID_BUTTON0: {
  65.         {
  66.         CL_Integer& sel0 = _box0->Selection();
  67.         UI_StringSequence& model = (UI_StringSequence&) _box0->Model();
  68.         sel0 = (sel0 + 1) % (model.Size());
  69.  
  70.         CL_Integer& sel1 = _box1->Selection();
  71.         UI_StringSequence& model1 = (UI_StringSequence&) _box1->Model();
  72.         sel1 = (sel1 + 1) % (model1.Size());
  73.         // No break: Fall through....
  74.         }
  75.         
  76.     case ID_BOX0:
  77.     case ID_BOX1:
  78.         _lbl0->Title() = "Selection: '" + _box0->EditString() + "'";
  79.         _lbl1->Title() = "Selection: '" + _box1->EditString() + "'";
  80.         break;
  81.  
  82.     }
  83.  
  84.     default:
  85.         break;
  86.     }
  87.     return FALSE;
  88. }
  89.  
  90.  
  91.